package com.srit.identify.common.swagger;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

/**
 * @author hongzhangming
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {
//    @Value("${spring.profiles.active}")
//    private String profiles;
    @Bean
    public Docket docKet() {
        ParameterBuilder tokenPar = new ParameterBuilder();
        List<Parameter> pars = new ArrayList<>();
        tokenPar.name("Authorization").description("令牌").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
        pars.add(tokenPar.build());
        Docket docket;
//        if("dev".equals(profiles) || "test".equals(profiles)){
             docket =  new Docket(DocumentationType.SWAGGER_2)
                    .apiInfo(new ApiInfoBuilder()
                            .title("微校园Api接口文档")
                            .version("V1.0-SNAPSHOT")
                            .build())
                    .select()
                    .apis(RequestHandlerSelectors.basePackage("com.srit.identify.controller"))
                    .paths(PathSelectors.any())
                    .build()
                    .globalOperationParameters(pars);
//        }else {//隐藏swagger
//             docket =  new Docket(DocumentationType.SWAGGER_2)
//                    .apiInfo(new ApiInfoBuilder()
//                            .title("微校园Api接口文档").version("V1.0-SNAPSHOT")
//                            .build())
//                    .select()
//                    .apis(RequestHandlerSelectors.basePackage("com.hfut.wxy.controller"))
//                    .paths(PathSelectors.none())
//                    .build();
//        }
        return docket;
    }
}
